package com.yc.fav.mapper;

import com.yc.fav.entity.FavFavorite;
import com.yc.fav.entity.FavTag;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * <p>
 * 云收藏-标签表-5 Mapper 接口
 * </p>
 *
 * @author wz
 * @since 2022-11-06
 */
public interface FavTagMapper extends BaseMapper<FavTag> {

    //多对多关联 = 两个一对多
    @Select("select * from fav_tag")
    @Results(id="rm1",value ={
            @Result(column ="id", property = "id", id = true),
            @Result(column ="id", property = "favorites",
            many = @Many(select = "selectFavByTid")),
    })
    List<FavTag> selectAll();

    @Select("select * from fav_favorite a join fav_tag_favorite b on a.id=b.fid " +
    " where b.tid = #{tid}"
    )
    List<FavFavorite> selectFavByTid(int tid);

    @Update("update fav_tag set tcount = tcount + 1 where tname=#{tname}")
   public  int updateTcount(String tname);
}
